"use strict";
cc._RF.push(module, '1b254C1aPVGwab2cFAfGHGk', 'LevelLianXian_1');
// scripts/modes/normalMode/levelLianXian/base/LevelLianXian_1.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var comSpSkeleton_1 = require("../../../../engines/components/comSpSkeleton");
var gameEngine_1 = require("../../../../engines/gameEngine");
var LevelBase_1 = require("../../../../Game/Base/LevelBase");
var LevelLianXian_1Item_1 = require("./LevelLianXian_1Item");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var LevelLianXian_1 = /** @class */ (function (_super) {
    __extends(LevelLianXian_1, _super);
    function LevelLianXian_1() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /** 当前选中的节点 */
        _this.currentSelectNode = null;
        /** 之后选中的节点 */
        _this.afterSelectNode = null;
        /** 当前成功答对的数量 */
        _this.currentYesNum = 0;
        /** 控制画板相应（删除之前的) */
        _this.cishuNum = 1;
        /** 计时 */
        _this.time = 60;
        /** 计时器--计时的 */
        _this.timeDT = 0;
        /** 是否开始计时 */
        _this.isStartTime = false;
        _this.isPlaySound = false;
        _this.errorSubTimeNum = 5;
        /** 画布组件 */
        _this.ctx1 = null;
        /** 计时Label */
        _this.timeLabel = null;
        /** */
        _this.countDownLabel = null;
        /** 画板--用于连续显示直线 */
        _this.DrawingBoard = null;
        /** 画板--用于存储 */
        _this.DrawingBoard1 = null;
        _this.sounds = [];
        _this.leftNode = null;
        _this.rightNode = null;
        _this.isCountDown = true;
        _this.needCount = 8;
        _this.levelName = "";
        _this.isPlaySoundNode = null;
        _this.soundId = null;
        _this.allPointPath = [];
        /** 连线成功之后还能不能继续点击item */
        _this.itemVaildIsClick = true;
        _this.timeDaoJiShi = 5;
        _this.canTouch = true;
        _this.allCheckDone = false;
        return _this;
    }
    /**
     * 添加一个路径点
     */
    LevelLianXian_1.prototype.addOnePointPath = function (Point) {
        this.allPointPath.push(Point);
        // console.log(this.allPointPath,">>>>>>>>>>>>>>>>")
    };
    /**
     * 移除一个路径点
     */
    LevelLianXian_1.prototype.removeOnePointPath = function (point) {
        if (!point)
            return;
        var index = this.checkOnePointInIndex(point);
        // console.log(index,"index????")
        if (index > -1) {
            this.allPointPath.splice(index, 1);
        }
    };
    /**
     * 获取路径点在数组中的索引
     */
    LevelLianXian_1.prototype.checkOnePointInIndex = function (point) {
        return this.allPointPath.findIndex(function (wayPoint) {
            return point.startNode.uuid == wayPoint.startNode.uuid && point.endNode.uuid == wayPoint.endNode.uuid;
        });
    };
    /**
     * 重绘所有路径点
     */
    LevelLianXian_1.prototype.redrawAllPointPath = function () {
        var graphics = this.DrawingBoard1.getComponent(cc.Graphics);
        graphics.clear();
        for (var i = 0; i < this.allPointPath.length; i++) {
            var pointPath = this.allPointPath[i];
            graphics.strokeColor = pointPath.color;
            var startVec = pointPath.startNode.getComponent(LevelLianXian_1Item_1.default).getNodePos(pointPath.startNode);
            var endVec = pointPath.startNode.getComponent(LevelLianXian_1Item_1.default).getNodePos(pointPath.endNode);
            graphics.moveTo(startVec.x, startVec.y);
            graphics.lineTo(endVec.x, endVec.y);
            graphics.stroke();
        }
    };
    LevelLianXian_1.prototype.onLoad = function () {
        _super.prototype.onLoad.call(this);
        gameEngine_1.default.getManagers().soundMgr.loadSoundBundle(this.levelName);
    };
    LevelLianXian_1.prototype.start = function () {
        _super.prototype.start.call(this);
        this.init();
    };
    LevelLianXian_1.prototype.init = function () {
        this.timeLabel.getComponent(cc.Label).string = "" + this.time;
        this.ctx1 = this.DrawingBoard.getComponent(cc.Graphics);
        this.currentSelectNode = null;
        this.afterSelectNode = null;
        this.timeLabel.active = this.isCountDown;
        this.countDownLabel.active = this.isCountDown;
    };
    LevelLianXian_1.prototype.pauseGame = function () {
        this.isStartTime = false;
        if (this.isPlaySoundNode) {
            cc.audioEngine.pauseAllEffects();
            this.isPlaySoundNode.getComponent(LevelLianXian_1Item_1.default).isStartSoundTime = false;
            this.isPlaySoundNode.getChildByName("BoFang").getComponent(comSpSkeleton_1.default).timeScale = 0;
        }
    };
    LevelLianXian_1.prototype.resumeGame = function () {
        this.isStartTime = true;
        if (this.isPlaySoundNode) {
            cc.audioEngine.resumeAllEffects();
            this.isPlaySoundNode.getComponent(LevelLianXian_1Item_1.default).isStartSoundTime = true;
            this.isPlaySoundNode.getChildByName("BoFang").getComponent(comSpSkeleton_1.default).timeScale = 1;
        }
    };
    LevelLianXian_1.prototype.touchScene = function (e) {
        var pos = e.getLocation();
        pos = this.node.convertToNodeSpaceAR(pos);
        //    let node = cc.instantiate(this.md);
        //    mainRoot.UIRoot.addChild(node);
        //    node.setPosition(pos);
        //    node.getComponent(comSpSkeleton).playAnimation("animation").start(false).onComplete(1, () => {
        //        node.removeFromParent();
        //    });
    };
    LevelLianXian_1.prototype.stopSound = function () {
        if (this.soundId != null) {
            gameEngine_1.managers().soundMgr.stopSound(this.soundId);
            this.soundId = null;
            this.isPlaySoundNode.getComponent(LevelLianXian_1Item_1.default).init();
            this.isPlaySoundNode.getComponent(LevelLianXian_1Item_1.default).stopSoundAni();
            this.isPlaySoundNode = null;
        }
    };
    LevelLianXian_1.prototype.update = function (dt) {
        if (!this.isCountDown)
            return;
        if (this.isStartTime) {
            if (this.allCheckDone)
                return;
            this.timeDT += dt;
            if (this.timeDT >= 1) {
                this.time--;
                this.timeDT = 0;
                this.timeLabel.getComponent(cc.Label).string = "" + this.time;
                if (this.time <= this.timeDaoJiShi && !this.isPlaySoundNode) {
                    gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/daojishi");
                }
            }
            if (this.time <= 0) {
                this.isStartTime = false;
                this.isPlaySound = true;
                this.Lose(3);
            }
        }
    };
    //    Lose(time?: number) {
    //        if (this.hadEnd) { return; }
    //        this.hadEnd = true;
    //        let delayTime: number = 2;
    //        if (time) {
    //            delayTime = time;
    //        }
    //        managers().soundMgr.stopAllSound();
    //        this.timeLabel.getComponent(cc.Label).string ="0";
    //        managers().soundMgr.playSound('mainSound/zaojulose');
    //        // this.ShowObj("Xz_Cw", (node: cc.Node) => {
    //        //     if(position)
    //        //         node.setPosition(position);
    //        // });
    //        this.scheduleOnce(() => {
    //            managers().soundMgr.playSound('mainSound/inLevel');
    //            // let losePrams: ILosePagePrams = {
    //            //     mode: this.m_mode,
    //            //     loseText: this.levelInfo.loseText,
    //            //     tips: this.levelInfo.tips,
    //            //     index: this.levelInfo.level
    //            // };
    //            // mainRoot.UISystem.OpenPage(PAGE.LOSEPAGE, losePrams);
    //            mainRoot.LevelSystem.LoadLevel(mainRoot.LevelSystem.GetSignleLevelInfo(this.m_mode).bundleName, this.m_mode);
    //            mainRoot.UISystem.CloseAllPage();
    //        }, delayTime);
    //    }
    LevelLianXian_1.prototype.errorSubTime = function () {
        if (this.isCountDown) {
            var afterNode = this.afterSelectNode;
            var pos = afterNode.convertToWorldSpaceAR(cc.v2());
            var node_1 = cc.instantiate(this.timeLabel);
            node_1.name = "lb";
            node_1.setParent(this.timeLabel.parent);
            node_1.setPosition(this.timeLabel.parent.convertToNodeSpaceAR(pos));
            var rotation = afterNode.getComponent(LevelLianXian_1Item_1.default).nodeRotation;
            var width = -afterNode.getChildByName("bg").width / 2;
            switch (rotation) {
                case 0: {
                    width = Math.abs(width);
                    break;
                }
            }
            node_1.x += width;
            this.time -= this.errorSubTimeNum;
            node_1.y += 25;
            node_1.getComponent(cc.Label).string = "-" + this.errorSubTimeNum;
            if (this.time <= 0) {
                this.timeLabel.getComponent(cc.Label).string = "0";
            }
            var speed = 1000;
            var time = node_1.getPosition().mag() / speed;
            // console.log(node.getPosition().mag(),speed,time,">>>>>>>>>>>>")
            cc.tween(node_1).by(0.5, { y: 20 }).call(function () {
                node_1.destroy();
                node_1.removeFromParent();
            }).start();
        }
    };
    LevelLianXian_1.prototype.checkWin = function () {
        /** 判断当前答对的数量 达到目标时 调用胜利方法 */
        var leftNodes = this.leftNode.children;
        for (var i = 0; i < leftNodes.length; i++) {
            var n = leftNodes[i];
            if (!n.getComponent(LevelLianXian_1Item_1.default).currentWayPoint) {
                return;
            }
        }
        this.canTouch = false;
        this.Win(2);
        this.isStartTime = false;
        this.isPlaySound = true;
        if (this.currentYesNum >= this.needCount) {
        }
    };
    LevelLianXian_1.prototype.isAllCheckDone = function () {
        var allDone = true;
        var leftNodes = this.leftNode.children;
        for (var i = 0; i < leftNodes.length; i++) {
            var n = leftNodes[i];
            if (!n.getComponent(LevelLianXian_1Item_1.default).currentWayPoint) {
                allDone = false;
            }
        }
        this.allCheckDone = allDone;
    };
    LevelLianXian_1.prototype.binGoAni = function (num) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
    };
    __decorate([
        property({ tooltip: "倒计时" })
    ], LevelLianXian_1.prototype, "time", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "计时Label" })
    ], LevelLianXian_1.prototype, "timeLabel", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "倒计时文本" })
    ], LevelLianXian_1.prototype, "countDownLabel", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "画板-DrawingBoard" })
    ], LevelLianXian_1.prototype, "DrawingBoard", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "画板-DrawingBoard1" })
    ], LevelLianXian_1.prototype, "DrawingBoard1", void 0);
    __decorate([
        property({ type: cc.String })
    ], LevelLianXian_1.prototype, "sounds", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "左边节点" })
    ], LevelLianXian_1.prototype, "leftNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "右边节点" })
    ], LevelLianXian_1.prototype, "rightNode", void 0);
    __decorate([
        property({ displayName: '是否有倒计时' })
    ], LevelLianXian_1.prototype, "isCountDown", void 0);
    __decorate([
        property()
    ], LevelLianXian_1.prototype, "needCount", void 0);
    __decorate([
        property()
    ], LevelLianXian_1.prototype, "levelName", void 0);
    __decorate([
        property()
    ], LevelLianXian_1.prototype, "itemVaildIsClick", void 0);
    LevelLianXian_1 = __decorate([
        ccclass
    ], LevelLianXian_1);
    return LevelLianXian_1;
}(LevelBase_1.default));
exports.default = LevelLianXian_1;

cc._RF.pop();